/*
 * @Description:
 * @Author: fhw
 * @Date: 2023-02-21 20:39:33
 */
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
import { IdDto, PageDto } from 'src/common/dto/dto';
import { FindOperator } from 'typeorm';

export class GetRolePageDto extends PageDto {
  @ApiPropertyOptional({
    type: String,
    name: 'rolename',
    description: '角色名称',
  })
  public readonly rolename?: FindOperator<string>;

  @ApiPropertyOptional({
    type: Number,
    name: 'isEnable',
    description: '是否启用,0:否；1:是',
  })
  public readonly isEnable?: number;
}
export class CreateRoleDto {
  /** 角色名称 */
  @IsNotEmpty({ message: '角色名称不能为空' })
  @ApiProperty({
    type: String,
    name: 'rolename',
    description: '角色名称',
  })
  public readonly rolename: string;
  /** 描述 */
  @IsNotEmpty({ message: '描述不能为空' })
  @ApiProperty({
    type: String,
    name: 'description',
    description: '描述',
  })
  public readonly description: string;
  /** 是否启用。0：否，1：是 */
  @IsEnum([0, 1], { message: '只能传入0, 1' }) //枚举
  @IsNotEmpty({ message: '是否启用。0：否，1：是' })
  @ApiProperty({
    type: Number,
    name: 'isEnable',
    description: '是否启用。0：否，1：是',
    enum: [0, 1],
  })
  public readonly isEnable?: number;
}
export class UpdateRoleDto extends CreateRoleDto implements IdDto {
  @ApiProperty({
    type: Number,
    name: 'id',
    description: '按钮id',
  })
  public readonly id: number;
}
export class RoleAuthConfigDto extends IdDto {
  @IsNotEmpty({ message: '菜单权限不能为空' })
  @IsString({ message: '菜单权限不是字符串' })
  @ApiProperty({
    type: String,
    name: 'menu',
    description: '菜单权限',
  })
  public readonly menu: string;
}
